﻿
/*
NAILSUPERSTORE ® COMPANY
 
[HISTORY]
Created By  	: NGUYEN VAN TY
Created Date	: 12/13/2010
Modified By     :
Modified Date   :
Note            :

*/

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using CommonTagTime;
using CommonTagTime.ModelObject;
using CommonTagTime.Business;
namespace CommonTagTime.DataAccess
{
    public class daoState
    {
        public daoState()
        {

        }
        public StateCollection GetByCountry(string countryCode)
        {
            clsSQL clsSQL = new clsSQL();
            SqlParameter[] para = new SqlParameter[1];
            SqlDataReader de;
            StateCollection items = new StateCollection();

            try
            {
                para[0] = new SqlParameter("CountryCode", SqlDbType.NVarChar);
                para[0].Value = countryCode;
                de = clsSQL.SPDataReader("State_GetByCountry", para);
                while (de.Read())
                {
                    State item = Load(de);
                    items.Add(item);
                }

                de.Close();              
                de.Dispose();
            }
            catch (Exception e)
            {
                clsFile.WriteLog("daoState", "GetByCountry(countryCode)", e.ToString());
            }
            finally
            {
                de = null;
                clsSQL.Dispose();
                clsSQL = null;
            }

            return items;
        }

        public StateCollection GetByCountryId(int countryId)
        {
            clsSQL clsSQL = new clsSQL();
            SqlParameter[] para = new SqlParameter[1];
            SqlDataReader de;
            StateCollection items = new StateCollection();

            try
            {
                para[0] = new SqlParameter("CountryId", SqlDbType.Int);
                para[0].Value = countryId;
                de = clsSQL.SPDataReader("State_GetByCountryID", para);
                while (de.Read())
                {
                    State item = Load(de);
                    items.Add(item);
                }

                de.Close();
                de.Dispose();
            }
            catch (Exception e)
            {
                clsFile.WriteLog("daoState", "GetByCountryId(int countryId)", e.ToString());
            }
            finally
            {
                de = null;
                clsSQL.Dispose();
                clsSQL = null;
            }

            return items;
        }



        private State Load(IDataReader de)
        {
            State item = new State();

            item.StateId = clsConvert.DbToInt("StateId", de);
            item.StateName = clsConvert.DbToString("StateName", de);
            item.StateCode = clsConvert.DbToString("StateCode", de);
            item.CountryCode = clsConvert.DbToString("CountryCode", de);            
            return item;
            // de.P
            //int intLogID = Convert.ToInt32(_comm.Parameters["@LogID"].Value);
        }

      

     
       
      


    }
}

